jQuery(document).ready(function () {
    selectList();
    $("#resetBtn").on("click",function () {
        $("#userName").val("");
        $("#userId").val("");
        $("#userDepart").val("");
        $("#userRole").val("");
        $("#telephone").val("");
    })
});
function queryParams(params) {
    return getQueryParams(params, "searchForm");
}
function selectList(){
    $('#userTable').bootstrapTable("destroy");
    $('#userTable').bootstrapTable({
        method: "post",
        url: rootPath+"/userManage/ajax/getUserList",
        showExport : true,
        exportTypes: ['excel'],//['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
        Icons:'glyphicon-export',
        exportOptions:{
            ignoreColumn: [0],  //忽略某一列的索引
            fileName: '人员列表',  //文件名称设置
            worksheetName: 'sheet1',  //表格工作区名称
            tableName: '人员列表'
        },
        exportDataType : 'all'
    });
}
function addUser() {
    layer.open({
        type: 2,
        title: "添加人员",
        shadeClose: false,
        shade: 0.8,
        area: ['70%', '85%'],
        content: rootPath + "/userManage/toPage/addUserView?decorator=decorator_blank",
        maxmin: true
    });
}
function updUserInfo() {
    var selections = $('#userTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        layer.msg('请选择一行数据进行操作！', function () {
        });
        return;
    }
    if(selections[0].state =='离职'){
        layer.alert("此员工为“离职”状态，不可执行修改操作！");
        return;
    }
    if(selections[0].role_id =="11"|| selections[0].role_id =="21"||selections[0].role_id =="31"){
        if ($("#loginUserRole").val()!='21'){
            layer.msg("当前权限不可对其修改！",function () {
            });
            return;
        }
    }
    layer.open({
        type: 2,
        title: "修改员工信息",
        shadeClose: false,
        shade: 0.8,
        area: ['70%', '85%'],
        content: rootPath + "/userManage/toPage/updUserView?decorator=decorator_blank&userId="+selections[0].user_id,
        maxmin: true
    });
}
function doUserIn() {
    var selections = $('#userTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        layer.msg('请选择一行数据进行操作！', function () {
        });
        return;
    }
    if(selections[0].state =='离职'||selections[0].state =='在职'){
        layer.alert("此员工状态下，不可再次确定入职！");
        return;
    }
    if(selections[0].role_id =="11"|| selections[0].role_id =="21"||selections[0].role_id =="31"){
        if ($("#loginUserRole").val()!='21'){
            layer.msg("当前权限不可对其操作！",function () {
            });
            return;
        }
    }
    var userId = selections[0].user_id;
    layer.open({
        content: '确定此员工正式入职？',
        btn: ['确定', "取消"],
        shade: false,
        offset: '200px',
        yes: function (index, layero) {
            $.ajax({
                type: "POST",
                url: rootPath + "/userManage/ajax/doUserIn",
                data:{userId:userId},
                dataType: "json",
                success : function(data) {
                    $("#userTable").bootstrapTable('refresh');//刷新表格
                    if(data.code == '0000') {
                        layer.msg(data.msg, {icon: 1});
                    }else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                error:function(){
                    layer.msg("操作出错！",{icon: 2});
                }
            });
        },
        cancel: function (index) {
        }
    });
}
function alreadyLeave() {
    var selections = $('#userTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        layer.msg('请选择一行数据进行操作！', function () {
        });
        return;
    }
    if(selections[0].state =='离职'){
        layer.alert("此员工为“离职”状态，不可再次执行离职操作！");
        return;
    }
    if(selections[0].role_id =="11"|| selections[0].role_id =="21"||selections[0].role_id =="31"){
        if ($("#loginUserRole").val()!='21'){
            layer.msg("当前权限不可对其操作！",function () {
            });
            return;
        }
    }
    var userId = selections[0].user_id;
    layer.open({
        content: '确定此员工正式离职？',
        btn: ['确定', "取消"],
        shade: false,
        offset: '200px',
        yes: function (index, layero) {
            $.ajax({
                type: "POST",
                url: rootPath + "/userManage/ajax/alreadyLeave",
                data:{userId:userId},
                dataType: "json",
                success : function(data) {
                    $("#userTable").bootstrapTable('refresh');//刷新表格
                    if(data.code == '0000') {
                        layer.msg(data.msg, {icon: 1});
                    }else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                error:function(){
                    layer.msg("操作出错！",{icon: 2});
                }
            });
        },
        cancel: function (index) {
        }
    });
}